Repository navigation
Conversation
`_ZMQPipelineConnectorProxy.connect_recv` returned as soon as the SUB socket was connected, but a subscription takes a round trip through the proxy before the XPUB side starts forwarding. A sender that connected and published immediately could therefore have its first messages dropped, which surfaced as a flake in the Ray + ZMQ proxy integration test on GitHub Actions. - Extend the settle delay from 0.1s to 0.5s, which covered the observed propagation window in local reproduction. - Mark the affected integration test as flaky with 3 reruns, so a residual race is retried rather than failing the run. Split out of #284, where it was originally found: it is unrelated to the message data classes and deserves its own review. The delay is a mitigation, not a fix; a proper solution would confirm subscription propagation instead of waiting.
|
Benchmark comparison for |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
chrisk314
added a commit
that referenced
this pull request
Dec 5, 2026
# Summary Implements #102: feat: Base component for external communication (#102). Adds `MessageDataReader` / `MessageDataWriter` for reading and writing **records** through a pub/sub broker - the broker equivalent of `FileReader`/`FileWriter`, where each message carries one record and `field_names` become the component's outputs (reader) or inputs (writer). Both extend the existing `DataReader`/`DataWriter` bases, adding what a broker needs and a finite source does not: a long-lived connection, reconnection with backoff, and acknowledgment. Two implementations are included: **Google Cloud PubSub** and **AWS SQS/SNS**. Apache Kafka is split out into draft PR #298 - see the note at the bottom for why. **Integration tests against real infrastructure are deliberately deferred** - no AWS/GCP accounts or broker resources exist yet. Terraform for the required PubSub topic/subscription and SNS topic/SQS queue lives in `plugboard-infra` (`terraform/ci-data-message-testing`), and `plugboard-infra/docs/running-message-data-tests.md` describes wiring its outputs into this suite. All 104 tests here are mock-based, so no credentials are needed. # Changes **Base classes** - `MessageDataReader` / `MessageDataWriter` extend `DataReader` / `DataWriter` (buffer, input binding and batching are inherited, not copied), adding `_connect`, `_disconnect`, `_receive`/`_send`, `_convert`, and `_ack` (reader). - Retry, exponential backoff and reconnect live in one shared place: `plugboard/utils/retry.py`, with a frozen `RetryPolicy` value object used by both bases. - Broker exceptions (`MessageBrokerConnectionError` / `TransientError` / `PermanentError`) are raised and honoured: each implementation maps its SDK's failures onto them, and permanent errors skip retries that cannot help. - Settings for GCP/AWS are read as constructor fallbacks (`GCP_PUBSUB_PROJECT_ID`, `AWS_REGION`); explicit arguments win. - All four concrete classes are exported from `plugboard.library`. **Implementations** - `GCPPubSubDataReader` / `GCPPubSubDataWriter` (`google-cloud-pubsub`) - every synchronous PubSub call is dispatched to a worker thread, so a pull or publish never stalls the shared event loop. - `AWSSQSDataReader` / `AWSSNSDataWriter` (`aiobotocore`) - long polling, `delete_message_batch` for acks, and the 10-message SQS cap is logged rather than applied silently. **Packaging**: optional extras `gcp-pubsub` and `aws-messaging`; the broker SDKs are also declared in the `test` dependency group, which is what lets the tests import the real client and error types. **Docs**: new [Message Data](https://docs.plugboard.dev/usage/message-data/) usage page (extras, worked example, delivery semantics), broker settings in the configuration page, new extras in the README. # Behaviour worth knowing - **An empty poll is not the end of the stream.** A reader started before its producer keeps waiting and picks up messages as they arrive, like `WebsocketReader`. A subclass signals a genuinely exhausted source by raising `NoMoreDataException`, which closes the IO as other data readers do. - **Messages are acknowledged after they are processed.** A batch fetched from the broker is acked only once all of its records have been published downstream, so a crash mid-batch leaves the unread messages for redelivery (at-least-once). Unconsumed pre-fetched messages are deliberately left unacked. - **Sends are not cancelled at teardown**: an in-flight batch is awaited (and any failure logged) rather than dropped. # Testing - 104 unit tests, all against teardown-aware `monkeypatch` fixtures rather than global `sys.modules` mocks, asserting broker calls and arguments rather than private attribute identity. - Coverage for the paths the review flagged as untested: retry exhaustion and the delay cap, empty-batch handling, SDK error mapping, reconnect/disconnect failures, pending-send failure at teardown, and ack timing. - Branch coverage of the new modules: `utils/retry.py` 100%, `message_reader.py` 95%, `message_writer.py` 94%, `gcp_pubsub_io.py` 94%, `aws_messaging_io.py` 95% - the remaining misses are abstract-method bodies. - `ruff check`, `ruff format --check`, `ty` over `plugboard/`, `plugboard-schemas/` and `tests/` pass; `mkdocs build` is clean. - Full unit suite: 387 passed, 6 skipped. Integration suite against the compose services: 141 passed, 1 pre-existing ZMQ flake (`test_process_stop_event[LocalProcess-ZMQConnector-...]`), which passes on repeat runs in isolation and is addressed in #297. # Related - #298 (draft) - the Apache Kafka implementation and its tests, split out of this PR. - #297 - the ZMQ slow-joiner delay and flaky marker found while debugging this branch; split out as unrelated scope. - `plugboard-infra/terraform/ci-data-message-testing` - infrastructure for the deferred real-broker integration tests.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_ZMQPipelineConnectorProxy.connect_recvreturned as soon as the SUB socket was connected, but a subscription needs a round trip through the proxy before the XPUB side starts forwarding. A sender that connected and published immediately could therefore have its first messages dropped (the classic ZMQ slow-joiner problem). This surfaced as a flake in the Ray + ZMQ proxy integration test on GitHub Actions.Change
connect_recvfrom0.1sto0.5s, which covered the observed propagation window in local reproduction.@pytest.mark.flaky(reruns=3)so a residual race is retried rather than failing the run.Notes
This is split out of #284, where it was originally found and diagnosed - it is unrelated to the message data classes and belongs in its own review.
The delay is a mitigation rather than a fix. A proper solution would confirm subscription propagation (e.g. a probe message with acknowledgement, or a subscribe/forward handshake) instead of guessing a wait; happy to follow up that way if preferred.
No issue is filed for this yet.
Fixes #None